package com.weixx.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auther weixx
 * @Date 2022/2/27
 */
@Configuration
public class DirectRabbitMQConfig {

    //1：声明交换机注册direct模式的交换机
    @Bean
    public DirectExchange directExchange(){

        return new DirectExchange("direct_order_exchange",true,false);

    }
    //2：声明队列sms.direct.queue email.direct.queue,duanxin.direct.queue
    @Bean
    public Queue smsDirectQueue(){
        return new Queue("sms.direct.queue",true);
    }
    @Bean
    public Queue emailDirectQueue(){
        return new Queue("email.direct.queue",true);
    }
    @Bean
    public Queue duanxinDirectQueue(){
        return new Queue("duianxin.direct.queue",true);
    }

    //1：声明绑定关系（交换机和队列完成绑定关系）
    @Bean
    public Binding smsDirectBingding(){
        return BindingBuilder.bind(smsDirectQueue()).to(directExchange()).with("sms");
    }
    @Bean
    public Binding emailDirectBingding(){
        return BindingBuilder.bind(emailDirectQueue()).to(directExchange()).with("email");
    }
    @Bean
    public Binding duanxinDirectBingding(){
        return BindingBuilder.bind(duanxinDirectQueue()).to(directExchange()).with("duianxin");
    }

}
